import {reactive,onMounted,watch} from 'vue'
import {getSecondCategory} from '@/apis/category/index'
import {useRoute} from 'vue-router'

export const useCategory = ()=>{
    let route = useRoute()
    //二级分类数据
let topCategory = reactive({})
onMounted(()=>{
    getTopCategory()
   
  })
const getTopCategory = async() => {
    let res = await getSecondCategory(route.params.id)
    // 对象合并
   Object.assign(topCategory,res.result)
}
// 监视路由变化
watch(()=>route.params.id,()=>{
    getTopCategory()
  })
  return {
    topCategory
  }
}